<?PHP
class MHDEV_View_Helper_BackendMenu extends Zend_View_Helper_Abstract
{
	public function BackendMenu()
	{
		$output = ''; # init
		
		$auth		= Zend_Auth::getInstance();
		
		$request 	= Zend_Controller_Front::getInstance();
		$view 		= Zend_Layout::getMvcInstance()->getView();
		$action 	= $request->getRequest()->getActionName();
		$controller = $request->getRequest()->getControllerName();
		
		$db 		= Zend_Registry::get('db');	
		$result 	= $db->query('SELECT * FROM `backend_navigation` WHERE `hidden` = 0 ORDER BY `sort_id`');
		$rows 		= $result->fetchAll();
		
		foreach($rows AS $row) 
		{
			if($row['role'] != "")
			{
				$role = explode(',', $row['role']);
				
				if(in_array('guest', $role) && !$auth->hasIdentity())
				{
					// proceed ...
				}
				elseif(!$auth->hasIdentity() OR !in_array($auth->getIdentity()->role,$role))
				{
					continue;
				}
			}
			
			if($controller == $row['controller']) 
			{
				$cssStyle	= 'class="main_act"';
			}
			else
			{
				$cssStyle	= 'class="main_no"';
			}
			
			if($row['lang_key'] != 'null')
			{
				$title = Zend_Registry::get('lang')->_($row['lang_key']);	
			}
			else
			{
				$title = $row['title'];
			}
			
			if($row['is_spacer'] == 1)
			{
				$output .= '<li class="spacer">' . $title . '</li>';
			}
			else
			{
				$output .= '
				<li ' . $cssStyle . '>
					<a ' . $cssStyle . ' href="' . $view->url(array('module' => 'backend', 'controller' => $row['controller'], 'action' => $row['action']), $row['route'], true). '">' . $title . '</a>
				</li>';
			}
		}
		return $output;
	}
}
?>